package com.ty.day4;

import java.util.ArrayList;
import java.util.Objects;

/**
 * Created by IntelliJ IDEA.
 *
 * @author : txy
 * @create : 2023/11/27 10:43
 */
public class LIstDemo01 {
    public static void main(String[] args) {
        ArrayList<Point> list = new ArrayList<>();
        list.add(new Point(1,2));
        list.add(new Point(3,4));
        list.add(new Point(5,6));
        list.add(new Point(7,8));
        list.forEach((x)->{
            System.out.println(x.toString());
        });
        System.out.println("&&&&&&&&");
        System.out.println(list.get(2).toString());
        System.out.println("%%%%%%");
        list.set(3,new Point(5,6));
        for (Point point1 : list) {
            System.out.println(point1.toString());
        }
        System.out.println("^^^^^^");
//        list.remove(0);
        Point point = list.get(1);
        list.set(1,list.get(2));
        list.set(2,point);
        for (Point point1 : list) {
            System.out.println(point1.toString());
        }
        Point point1 = new Point(1, 2);
        boolean result = list.contains(point1);
        System.out.println(result);
        list.sort((x,y)->{return x.getX()- y.getX();});
        for (Point point2 : list) {
            System.out.println(point2);
        }
        int x=3,y=10;
        System.out.println((x++)*(--y));

    }
}

class Point{
    private Integer x;
    private Integer y;

    public Point(Integer x, Integer y) {
        this.x = x;
        this.y = y;
    }

    public Point() {
    }

    public Integer getX() {
        return x;
    }

    public void setX(Integer x) {
        this.x = x;
    }

    public Integer getY() {
        return y;
    }

    public void setY(Integer y) {
        this.y = y;
    }

    @Override
    public String toString() {
        return "Point{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Point point = (Point) o;
        return Objects.equals(x, point.x) && Objects.equals(y, point.y);
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }
}